<%--
    Document   : newjsp
    Created on : Jul 25, 2013, 11:01:57 AM
    Author     : ZzCFIzZ
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%--<link type="text/css" rel="stylesheet" href="css/commentCSS.css">--%>
    </head>
    <%
                Utility.CommentProcess.marshallXML(application.getRealPath("/") + "WEB-INF/XMLFiles/comment_load.xml", Integer.parseInt(request.getParameter("placeID")));
    %>
    <c:import url="WEB-INF/XMLFiles/comment.xsl" var="xslt"/>
    <c:import url="WEB-INF/XMLFiles/comment_load.xml" var="xml"/>
    <x:transform xml="${xml}" xslt="${xslt}">
        <x:param name="check" value="1"/>
    </x:transform>

    <body onload="FirstLoad()">
        <form action="Controller" name="Comment" onsubmit="return validateForm()">
            <input type="button" onclick="changeDisplay()" value="ReadMore" />
            <input type="button" onclick="changeDisplay2()" value="Close" /><br/><br/>
            <table border="0">

                <tbody>
                    <tr>
                        <td>Name</td>
                        <td><input type="text" name="txtNick" id="txtNick"/></td>
                    </tr>
                    <tr>
                        <td>Content</td>
                        <td><textarea rows="5" cols="40" name="txtComment" id="txtComment"></textarea></td>
                    </tr>
                </tbody>
            </table>
            <input type="submit" value="Submit" name="btAction"/>
            <input type="hidden" name="txtPlaceID" value="${param.placeID}" />
        </form>
    </body>
    <script type="text/javascript">
        var count = 4;
        function changeDisplay(){
            if(document.getElementById(count).style.display=="none"){
                for (var i=1;i<4;i++){
                    document.getElementById(count).style.display="block";
                    count++;
                }
            }
        }
        function changeDisplay2(){
            //load lai trang
            window.location.reload();
        }
        function FirstLoad(){
            for (var i=1;i<4;i++){
                document.getElementById(i).style.display="block";
            }
        }
        function validateForm(){
            var x=document.forms["Comment"]["txtNick"].value;
            var y=document.forms["Comment"]["txtComment"].value;
            var test=/\W$\W/;
            var rawFile = new XMLHttpRequest();
            var c;
            rawFile.open("GET", "check.txt", true);
            rawFile.onreadystatechange = function ()
            {
                if(rawFile.readyState == 4)
                {
                    var allText = rawFile.responseText;
                    c = allText.split('\n');
                    for (var i=0;i<(c.length-1);i++){
                        var k=new RegExp(c[i]);
                        if(k.test(x)){
                            alert("Khong duoc noi bay!!!");
                            return false;
                        }
                        if(k.test(y)){
                            alert("Khong duoc noi bay!!!");
                            return false;
                        }
                    }
                }
            }
            rawFile.send();
            var script=new RegExp("<\/script>");
            if(script.test(x)){
                alert("Please choose a different name");
                return false;
            }
            if(script.test(y)){
                alert("Please choose a different content");
                return false;
            }
            if(test.test(x)){
                alert("Nick must content character!!!");
                return false;
            }
            if(test.test(y)){
                alert("Content must be filled out");
                return false;
            }
            if(((x==null || x=="")&&(y==null || y=="")))
            {
                return false;
            }
            if ((x==null || x=="")&&(y!=null || y!=""))
            {
                alert("Nick must be filled out");
                return false;
            }
            if((y==null || y=="")&&(x!=null || x!=""))
            {
                alert("Comment must be filled out");
                return false;
            }
            if(x.toString().length<5 || x.toString().length>30)
            {
                alert("Nickname's length must be between 5 and 30 characters!!!");
                return false;
            }
            if(y.toString().length<15 || y.toString().length>300)
            {
                alert("Comment's length must be between 5 and 300 characters!!!");
                return false;
            }
        }
    </script>
</html>
